package edu.uclmgmu.bacteriosec.domain.data;

public class CallResult {
	private int callNumber;
	private String result;
	private MethodCatched catchedMethod;
	private TestCaseExecuted testCase;
	private String aspectClassFile;

	public CallResult(int callNumber, String aspectClassFile, MethodCatched catchedMethod, TestCaseExecuted testCase) {
		this.callNumber=callNumber;
		this.aspectClassFile=aspectClassFile;
		this.catchedMethod=catchedMethod;
		this.testCase=testCase;
	}

	static int contador=0;
	public void processResult(String result) {
		if (result==null || result.trim().length()==0)
			return;
		this.result="";
		String auxi=result.trim();
		String summary="";
		int i=0;
		while (i<auxi.length() && (auxi.charAt(i)=='.' || auxi.charAt(i)=='F' || auxi.charAt(i)=='E')) {
			summary+=auxi.charAt(i++);
		}
		System.out.println(contador++ + " <" + summary + ">");
		i=0;
		while (i<summary.length()) {
			char c=summary.charAt(i);
			if (i<summary.length()-1) {
				char cAde=summary.charAt(i+1);
				if (cAde=='.') {
					this.result+="P";
				} else if (cAde=='F') {
					// Failure
					this.result+="F";
					i++;
				} else if (cAde=='E') {
					this.result+="F";
					// Error
					i++;
				} else {
					// ??
					this.result+=cAde;
					i++;
				}
			} else {
				this.result+="P";
			}
			i++;
		}
	}
	
//	public static void main(String[] args) {
//		AspectExecutionResult aer=new AspectExecutionResult("caca");
//		aer.processResult(".F.F.F.Ej");
//		System.out.println(aer.getResult());
//	}

	public String getResult() {
		return result;
	}

	public int getCallNumber() {
		return this.callNumber;
	}

	public char getTestCaseResult(int index) {
		return this.result.charAt(index);
	}
	
	public MethodCatched getCatchedMethod() {
		return catchedMethod;
	}
	
	@Override
	public String toString() {
		return this.callNumber + "-> " + this.result;
	}

	public TestCaseExecuted getTestCase() {
		return testCase;
	}

	public String getAspectClassFile() {
		return aspectClassFile;
	}
}
